﻿<?php
require('configs/include.php');

class c_revisar_peticion extends super_controller {

    public function cerrar() {
        $typeSession = $_SESSION['user']['user'];
        if ($typeSession == $this->get->usuario) {
            $options['peticion']['lvl2'] = "by_oneuser";
            $cod['peticion']['user'] = $typeSession;
            $cod['peticion']['id'] = $this->get->id;
            $peticion = new peticion();
            $peticion->set('id', $this->get->id);
            $this->orm->connect();

            $this->orm->read_data(array("peticion"), $options, $cod);
            $peticiones = $this->orm->get_objects("peticion");
            //print_r2($peticiones);
            if (isset($peticiones[0])) {
                $this->orm->update_data("by_id", $peticion);
            } else {
                $this->engine->display('sinPermisos.tpl');
            }

            $this->orm->close();
        }
    }

    public function display() {
        $options['peticion']['lvl2'] = "by_state";
        $this->orm->connect();
        $this->orm->read_data(array("peticion"), $options);
        $peticiones = $this->orm->get_objects("peticion");
        $this->orm->close();
        $this->engine->assign('peticiones', $peticiones);
        $varAux = $this->gvar['n_index'] . " -> " . $this->gvar['n_request'];
        $this->engine->assign('ubicationPath', $varAux);
        $this->engine->display('header.tpl');
        $this->engine->display('revisar_peticion.tpl');
        $this->engine->display('footer.tpl');
    }

    public function run() {
        $typeSession = $_SESSION['usuario']['tipo'];
        if ($typeSession == "lider" || $typeSession == "programador" || $typeSession == "intermediario") {
            try {
                if (isset($this->get->option)) {
                    $this->{$this->get->option}();
                }
            } catch (Exception $e) {
                $this->error = 1;
                $this->msg_warning = $e->getMessage();
                $this->img_warning = "incorrect.png";
                $this->engine->assign('type_warning', $this->type_warning);
                $this->engine->assign('msg_warning', $this->msg_warning);
                $this->engine->assign('img_warning', $this->img_warning);
                $this->temp_aux = 'message.tpl';
            }
            $this->display();
        } else {
            $this->engine->display('header.tpl');
            $this->engine->display('sinPermisos.tpl');
            $this->engine->display('footer.tpl');
        }
    }

}

$call = new c_revisar_peticion();
$call->run();
?>